
#include "stdafx.h"
#include "SLFont.h"

CSLFontContainer* CSLFontContainer::m_pInstance = 0;

CSLFontContainer* CSLFontContainer::GetInstance()
{
	if(m_pInstance == 0)
	{
		m_pInstance = new CSLFontContainer;
	}
	return m_pInstance;
}

CSLFontContainer::CSLFontContainer()
{
}

CSLFontContainer::~CSLFontContainer()
{
	if(m_pInstance != 0)
	{
		delete m_pInstance;
		m_pInstance = 0;
	}
}

BOOL CSLFontContainer::IsValidFont(LPLOGFONT pLogFont)
{
	_ASSERT( pLogFont );
	if( NULL == pLogFont )
		return FALSE;
	for( int i=0; i<sizeof(LOGFONT); i++ )
	{
		BYTE	bt	=	*( ((LPBYTE)pLogFont) + i );
		if( 0 != bt )
			return TRUE;
	}
	return FALSE;
}

void CSLFontContainer::GetSLFont(OUT LPLOGFONT pLogFont)
{
	_ASSERT(pLogFont);
	if(NULL == pLogFont)
		return;
	
	if(IsValidFont(&m_logfont))
	{
		memcpy(pLogFont, &m_logfont, sizeof(LOGFONT));
	}
	else
	{
		LOGFONT lf;
		GetObject(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &lf);
		memcpy(pLogFont, &lf, sizeof(LOGFONT));
	}
}
void CSLFontContainer::SetSLFont(LPLOGFONT pLogFont)
{
	_ASSERT( pLogFont );
	if( pLogFont )
		memcpy(&m_logfont, pLogFont, sizeof(LOGFONT));
}